package db;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import model.type.SubjectAttributeType;


public class SubjectAttributeTypeDAO {
	private static final String TABLE = "subject_attribute_type";	
	private static String onSqlError = "SQL statement fault";
		
	@SuppressWarnings("unused")
	private static final String 
		ID_FIELD = "subject_attribute_type",			
		SUBJECT_TYPE_FIELD = "subject_type_fk",
		TYPE_NAME_FIELD = "type_name",
		DATA_TYPE_FIELD = "data_type",
		ORDERBY_FIELD = "orderby",
		REQUIRED_FIELD = "required",
		MULTIPLE_ATTRIBUTES_FIELD = "multiple_attributes",
		CREATED_BY_DEFAULT_FIELD = "created_by_default";
	
	public static ArrayList<SubjectAttributeType> getAll() {			
		try{				
			Statement st = ImbiConnection.getConnection().createStatement();
			st.executeQuery("SELECT * FROM "+TABLE);
			ResultSet r = st.getResultSet();			
			ArrayList<SubjectAttributeType> attributeTypes = new ArrayList<SubjectAttributeType>();
						
			while(r.next()){				
				attributeTypes.add(
					new SubjectAttributeType(
						r.getInt(1), 
						r.getInt(2),
						r.getString(3),
						r.getInt(4),
						r.getInt(5),
						r.getString(6),
						r.getString(7),
						r.getString(8)
					)
				);
			}
			return attributeTypes;
		} catch (SQLException s){
				System.out.println(onSqlError);				
				return null;
		}		
	}		
}
